<?php
use think\Db;
use think\facade\Env;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/23
 * Time: 11:50
 */

/**
 *
 * @return int
 */


/**
 * 获取用户名
 * @return int
 */
function get_user_name($id){
    $user_nickname=Db::name('user')->where('id',$id)->value('user_login');
    return $user_nickname;
}
/**
 * 取数组第一个
 * @return int
 */
function array_first($arr){
    return $arr[0];
}
/**
 * 秒转小时取一位小数
 * @return int
 */
function s_to_h($s){
    $h=number_format($s/3600,3);
    return $h;
}

/**
 * 获取二维码完整url
 * @return int
 */
function get_qrcode($uuid){
    $folder_path = request()->domain().'/upload/qrcode/';
    $filename = $folder_path.$uuid.'.png';
    return $filename;
}

/**
 * 获取富文本中第一张图片
 * @return int
 */
function cmf_get_content_first_image($content)
{
    //import('phpQuery.phpQuery', EXTEND_PATH);
    \phpQuery::newDocumentHTML($content);
    $pq         = pq(null);
    $images     = $pq->find("img");
    if ($images->length) {
        foreach ($images as $img) {
            $img            = pq($img);
            $image   = $img->attr("src");
            \phpQuery::$documents = null;
            return cmf_get_image_url($image);
        }
    }

}
/**
 * 状态为0未使用销分券第一次获取并改变销分券状态,便不会再访问此接口
 * @return int
 */
//function get_code_status($id){
//   $result=http_test($id);
//    if($result['status']==1){
//        Db::name('point_exchange_log')->where('id',$id)->update(['status'=>1]);
//    }
//    return $result['status'];
//
//}
//function http_test($id){
//    $result=[];
//    $result['status']=$id%2;
//    return $result;
//}

function http_post($url,$data){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER,array());
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}